<template>
    <!--最大div-->
    <div style="margin-top: -10px">
        <!--新建栏-->
        <div style="border:1px solid #BFBFBF;padding: 10px;background-color: white;margin-top: 10px;height: 40px">
            <el-row :gutter="24">
                <el-col :span="2">
                    <span style="font-size: 18px;line-height:40px;margin-left: 5px">订单列表</span>
                </el-col>
                <el-col :span="7">
                    <template>
                        <el-select v-model="value7" placeholder="请选择" @change="changebusni" style="width: 150px;margin-left: 20px">
                            <el-option
                                    v-for="item in options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </template>
                    <el-button style="background-color: #F05050;color: white;margin-left: 10px;" @click="cancelseek" icon="el-icon-back" v-show="seek" size="mini" round>解除搜索</el-button>
                </el-col>
                <el-col :span="9">
                    <el-input @keyup.enter.native="sousuo" placeholder="请输入搜索的信息" v-model="input23" style="width: 250px;">
                        <i slot="suffix" class="el-input__icon el-icon-search" @click="sousuo"></i>
                    </el-input>
                </el-col>
                <el-col :span="6">
                        <el-button @click="xz" style="margin-top:5px;margin-left:200px;" size="small"  type="primary">新建订单</el-button>
                </el-col>
            </el-row>
        </div>

        <!--表格数据框-->
        <div style="margin-top: 10px;border: 1px solid #BFBFBF;background-color: white">
            <div style="width: 100%;height: 40px;background-color: white;border-bottom: 1px solid #EBEEF5">
                <div class="operate" v-show="cjy">
                    <div class="selected—title" style="border-right: 0px;width: 150px">
                        场景：<span>{{value7}}</span>
                    </div>
                </div>
                <div class="operate" v-show="cje">
                    <div class="selected—title" >
                        已选中<span class="selected—count">{{count}}</span>项
                    </div>
                </div>
            </div>
            <el-table
                    :data="tableData4"
                    style="width: 100%"
                    max-height="450"
                    :default-sort = "{prop: 'date', order: 'descending'}"
                    @selection-change="handleSelectionChange">
                <el-table-column
                        prop="orderId"
                        type="selection"
                        width="50"
                        align="center">
                </el-table-column>
                <el-table-column
                        fixed
                        prop="orderNo"
                        label="订单编号"
                        sortable
                        align="center"
                        width="160">
                </el-table-column>
                <el-table-column
                        label="主题"
                        sortable
                        align="center"
                        width="160">
                    <template slot-scope="sp">
                        <a v-html="sp.row.orderTheme" class="businame" @click="dindanxq(sp.row)"></a>
                    </template>
                </el-table-column>
                <el-table-column
                        label="客户"
                        sortable
                        align="center"
                        width="150">
                    <template slot-scope="sp">
                        <a v-html="sp.row.clientId.clientName" class="businame" @click="kehutodetails(sp.row)"></a>
                    </template>
                </el-table-column>
                <el-table-column
                        label="合同"
                        sortable
                        align="center"
                        width="150">
                    <template slot-scope="sp">
                        <a v-html="sp.row.conId.conTheme" class="businame" @click="todetails(sp.row)"></a>
                    </template>h
                </el-table-column>
                <el-table-column
                        label="下单日期"
                        align="center"
                        sortable
                        width="130">
                    <template slot-scope="d">
                        {{d.row.orderTime | formatDate}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="完成日期"
                        align="center"
                        sortable
                        width="130">
                    <template slot-scope="d">
                        {{d.row.orderWctime | formatDate}}
                    </template>
                </el-table-column>
                <el-table-column
                        prop="orderTotal"
                        label="金额"
                        align="center"
                        width="120">
                </el-table-column>
                <el-table-column
                        label="剩余回款金额"
                        sortable
                        align="center"
                        width="150"
                        prop="orderReturned">
                </el-table-column>
                <el-table-column
                        label="开票金额"
                        sortable
                        align="center"
                        width="150"
                        prop="orderInvoice">
                </el-table-column>
                <el-table-column
                        prop="orderGross"
                        label="毛利"
                        sortable
                        align="center"
                        width="120">
                </el-table-column>
                <el-table-column
                        prop="orderExchange"
                        label="是否换货"
                        sortable
                        align="center"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="orderReturn"
                        label="是否退货"
                        align="center"
                        sortable
                        width="120">
                </el-table-column>
                <el-table-column
                        prop="orderState"
                        label="状态"
                        align="center"
                        sortable
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="orderJfzt"
                        label="交付状态"
                        align="center"
                        sortable
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="orderHkzt"
                        label="回款状态"
                        align="center"
                        sortable
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="orderRemark"
                        label="备注"
                        align="center"
                        sortable
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="orderPeople"
                        label="负责人"
                        align="center"
                        sortable
                        width="100">
                </el-table-column><el-table-column
                    fixed="right"
                    label="操作"
                    align="center"
                    width="150">
                <template slot-scope="d">
                    <!--如果是三个标签，后两个标签padding-left: 10px;-->
                    <i style="font-size:18px;color: #409EFF" @click="xiugai(d.row)" class="el-icon-edit"></i>
                    <svg @click="hueikuan(d.row)" title="aaa" style="padding-left:15px"  class="icon" aria-hidden="true">
                        <use xlink:href="#icon-huikuanjihua"></use>
                    </svg>
                    <svg @click="jiaofu(d.row)" title="aaa" style="padding-left:15px"  class="icon" aria-hidden="true">
                        <use xlink:href="#icon-jihuaxinxi"></use>
                    </svg>
                    <i style="font-size:18px;padding-left:15px;color: #409EFF" @click="sc(d.row)" class="el-icon-delete"></i>
                </template>
            </el-table-column>
            </el-table>
        </div>

        <!--分页框-->
        <div style="margin-top: 15px;border: 1px solid #BFBFBF;padding: 10px;background-color: white">
            <div style="text-align: center">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page.sync="currentpage"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="totalSize"
                >
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
    import Crypto  from '../router//secret.js'
    import {formatTimeToStr} from '../router//format.js'
    export default {
        name: "ZdindanZhuye",
        data() {
            return {
                multipleTable: [],//存放选中值的数组
                isOne:true,//选中项为1就出现添加跟进记录和修改
                seek:false,//解除搜索是否显示
                options: [
                    {
                        value: '回款中',
                        label: '回款中',
                    }, {
                        value: '已回款',
                        label: '已回款',

                    }, {
                        value: '交付中',
                        label: '交付中',
                    }, {
                        value: '已交付',
                        label: '已交付',
                    }, {
                        value: '已完成',
                        label: '已完成',
                    },  {
                        value: '有退换货',
                        label: '有退换货',
                    }, {
                        value: '无退换货',
                        label: '无退换货',
                    }
                ],
                value7:'',
                //场景一
                cjy:true,
                //场景二
                cje:false,
                //搜索框
                input23: '',
                //表格信息
                tableData4: [],
                //分页
                totalSize: 1,//数据总条数
                pageSize: 10,//页大小
                currentpage: 1//当前页面
            }
        },
        created:function () {
            if(this.$route.query.ys!=null){
                this.currentpage=this.$route.query.ys;
            }
            if(this.$route.query.ydx!=null){
                this.pageSize=this.$route.query.ydx;
            }
            this.biapgecx(this.currentpage,this.pageSize,this.input23,this.value7);
        },
        methods: {
            sc(cp){
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$axios.post("http://localhost:8088/dindan/delete",cp)
                        .then(v=>{
                            if(v.data==0){
                                this.$message({
                                    showClose: true,
                                    type: 'success',
                                    message: '删除成功!',
                                });
                                this.biapgecx(this.currentpage,this.pageSize,this.input23,this.value7);
                            }else {
                                this.$message({
                                    showClose: true,
                                    message: '有回款计划或交付计划无法删除',
                                    type: 'error'
                                });
                            }
                        }).catch()
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            /*跳客户详情转详情方法*/
            kehutodetails(rows){
                rows = escape(Crypto.set(rows.clientId.clientId)); // 加密数据
                this.$router.push({
                    path:'/tfyxq',
                    query: {
                        row:rows
                    }
                });
            },
            //回款方法
            hueikuan(cp){
                if(cp.orderReturned>0){
                    this.$router.push({
                        path:'/hkxinzen',
                        query: {dd:cp,ys:this.currentpage,ydx:this.pageSize,dz:'ddzy'}
                    });
                }else {
                    this.$message({
                        showClose: true,
                        message: '已完成回款无法回款',
                        type: 'error'
                    });
                }
            },
            jiaofu(cp){
                if(cp.orderJfzt!='已交付'){
                    this.$router.push({
                        path:'/jfxinzen',
                        query: {dd:cp,ys:this.currentpage,ydx:this.pageSize,dz:'ddzy'}
                    });
                }else {
                    this.$message({
                        showClose: true,
                        message: '已完成交付无产品可交付',
                        type: 'error'
                    });
                }
            },
            xz(){
                this.$router.push({
                    path:'/ddxinzen'
                });
            },
            //修改方法
            xiugai(cp){
                window.console.log(cp)
                this.$router.push({
                    path:'/ddxinzen',
                    query: {key:cp,ys:this.currentpage,ydx:this.pageSize}
                });
            },
            //发票查询方法
            biapgecx(currentpage,pageSize,search,value7){
                window.console.log(search);
                this.$axios.get("http://localhost:8088/dindan/list_dd2",{params:{page:currentpage,size:pageSize,search:search,search2: value7}})
                    .then(v=>{
                            this.tableData4 = v.data.rows;
                            this.totalSize = v.data.total;
                        }
                    ).catch()
            },
            /*跳转订单详情方法*/
            dindanxq(key){
                this.$router.push({
                    path:'/ddxianqin',
                    query: {
                        key:key
                    }
                })
            },
            /*跳转详情方法*/
            todetails(rows){
                this.$router.push({
                    path:'/business/details',
                    query: {
                        row:rows
                    }
                })
            },
            /*新建商机方法*/
            showmian(){

            },
            /*搜索框方法*/
            sousuo() {
                this.currentpage=1
                this.pageSize=10
                this.biapgecx(this.currentpage,this.pageSize,this.input23,this.value7);
            },
            /*分页数方法*/
            handleSizeChange(val) {
                this.biapgecx(this.currentpage,val,this.input23,this.value7);
            },
            /*当前页方法*/
            handleCurrentChange(val) {
                this.biapgecx(val,this.pageSize,this.input23,this.value7);
            },
            //复选框选中的
            handleSelectionChange(val) {
                this.multipleTable = val;//  this.multipleTable 选中的值
                if(this.multipleTable.length>0){
                    this.cjy=false;//第一行隐藏
                    this.cje=true;//批量操作栏出现
                }
                //选中项大于1不能执行添加跟进记录和修改按钮
                if(this.multipleTable.length>1){
                    this.isOne=false;
                }else if(this.multipleTable.length==0){//选中项为0时
                    this.cjy=true;//第一行出现
                    this.cje=false;//批量操作栏隐藏
                }else{
                    this.isOne=true;//添加跟进记录和修改出现
                }
                window.console.log(val);
            },
            /*选择类型商机方法*/
            changebusni(){
                if(this.value7!=''){
                    this.seek=true;
                }
                this.biapgecx(this.currentpage,this.pageSize,this.input23,this.value7);
            },
            /*解除选择类型商机方法*/
            cancelseek(){
                this.value7='';
                this.input23='';
                this.seek=false;
                this.biapgecx(this.currentpage,this.pageSize,this.input23,this.value7);
            }
        },
        computed:{
            count(){
                return this.multipleTable.length
            }
        },
        filters: {
            formatDate: function (time) {
                if (time != null && time != "") {
                    var date = new Date(time);
                    return formatTimeToStr(date, "yyyy-MM-dd");
                } else {
                    return "";
                }
            }
        }

    }
</script>

<style scoped>
    .icon {
        width: 1.3em;
        height: 1.3em;
        vertical-align: -0.15em;
        fill: currentColor;
        overflow: hidden;
        color:  #409EFF;
    }
    .addview:hover{
        color: white;
    }
    a{
        text-decoration: none;
        color: #409EFF;
    }
    a:hover{
        color: white;
    }
    .busin:hover{
        color: #3E84E9;
        cursor:pointer;
    }
    .businame{
        color: #606266;
    }
    .businame:hover{
        color: #409EFF;
        cursor:pointer;
    }
    .operate{
        float:left;
        font-size: 12px;
        height: 40px;
        padding: 0 20px;
        color: #777;
        background: white;
    }
    .selected—title{
        margin-top: 15px;
        margin-left: -6px;
        border-right: 1px solid #e6e6e6;
        width: 86px;
        height:20px;
        float: left;
    }
    .selected—title1{
        margin-top: 15px;
        border-right: 1px solid #e6e6e6;
        width: 86px;
        height:20px;
        float: left;
        cursor: pointer;
    }

    .selected—title1 span{
        margin-left: 24px;
    }
    .selected—title1 span:hover{
        color:#409eff;
    }
    .selected—title2{
        margin-top: 15px;
        border-right: 1px solid #e6e6e6;
        width: 129px;
        height:20px;
        float: left;
        cursor: pointer;
    }

    .selected—title2 span{
        margin-left: 24px;
    }
    .selected—title2 span:hover{
        color:#409eff;
    }
</style>